package com.qianxun.framework.util.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

public class HttpResponse {
        private HttpURLConnection connection;
        private byte[] response;

        public HttpResponse(HttpURLConnection connection, byte[] response) {
            super();
            this.connection = connection;
            this.response = response;
        }

        public String getHeader(String name) {
            return connection.getHeaderField(name);
        }

        public Map<String, List<String>> getHeaderFileds() {
            return connection.getHeaderFields();
        }

        public byte[] getResponse() {
            return response;
        }

        public int getStatus() {
            try {
                return connection.getResponseCode();
            } catch (IOException e) {
            }
            return -1;
        }

    @Override
    public String toString() {
        return new String(response);
    }

    public String toString(Charset charset){
            return new String(response ,charset);
    }
}